package lemna.top.chunyu.batch.step5;

import java.io.IOException;
import java.io.Writer;
import java.util.Date;

import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.file.FlatFileHeaderCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import lemna.top.chunyu.batch.step1.ChunYuService;

@Component
@StepScope
public class Step5Callback  implements FlatFileHeaderCallback{

	@Autowired
	ChunYuService chunYuService;
	

	@Value("#{jobParameters[date]}")
	Date date;
 

	@Override
	public void writeHeader(Writer writer) throws IOException {
		Long count = chunYuService.countSystemOut(date);
		Double sum = chunYuService.sumSystemOut(date);
		writer.write(String.format("%s|%s",count,sum));
		
	}

}
